﻿#pragma once

#ifndef BRIDGEANALYSIS_METHOD_FILE_H
#define BRIDGEANALYSIS_METHOD_FILE_H


int64_t createMethodFile_(const char *szMethodName, bool innerCall = true);
int64_t openMethodFile_(const char *szFileName, bool innerCall = true);
bool saveMethodFile_(int64_t nHandle, const char *szFileName, bool innerCall = true);
bool closeMethodFile_(int64_t nHandle, bool innerCall = true);
bool getMethodHead_(int64_t nHandle, int32_t nHandleType, TMethodHead *pBuffer, bool innerCall = true);
bool setMethodHead_(int64_t nHandle, int32_t nHandleType, const TMethodHead *pBuffer, bool innerCall = true);
bool getMethodEventList_(int64_t nHandle, int32_t nHandleType, TEventList *pBuffer, int32_t nBufferCount, int32_t *pDataCount, bool innerCall = true);
bool setMethodEventList_(int64_t nHandle, int32_t nHandleType, const TEventList *pBuffer, int32_t nBufferCount, bool innerCall = true);
bool getMethodCompList_(int64_t nHandle, int32_t nHandleType, TCompList *pBuffer, int32_t nBufferCount, int32_t *pDataCount, bool innerCall = true);
bool setMethodCompList_(int64_t nHandle, int32_t nHandleType, const TCompList *pBuffer, int32_t nBufferCount, bool innerCall = true);
bool getMethodGroupList_(int64_t nHandle, int32_t nHandleType, TGroupList *pBuffer, int32_t nBufferCount, int32_t *pDataCount, bool innerCall = true);
bool setMethodGroupList_(int64_t nHandle, int32_t nHandleType, const TGroupList *pBuffer, int32_t nBufferCount, bool innerCall = true);
bool getMethodSegmentList_(int64_t nHandle, int32_t nHandleType, TSegmentList *pBuffer, int32_t nBufferCount, int32_t *pDataCount, bool innerCall = true);
bool setMethodSegmentList_(int64_t nHandle, int32_t nHandleType, const TSegmentList *pBuffer, int32_t nBufferCount, bool innerCall = true);
bool getMethodCalibList_(int64_t nHandle, int32_t nHandleType, TCalibList *pBuffer, int32_t nBufferCount, int32_t *pDataCount, bool innerCall = true);
bool setMethodCalibList_(int64_t nHandle, int32_t nHandleType, const TCalibList *pBuffer, int32_t nBufferCount, bool innerCall = true);
bool getMethodCalibResult_(int64_t nHandle, int32_t nHandleType, TCalibResult *pBuffer, int32_t nBufferCount, int32_t *pDataCount, bool innerCall = true);
bool setMethodCalibResult_(int64_t nHandle, int32_t nHandleType, const TCalibResult *pBuffer, int32_t nBufferCount, bool innerCall = true);

// 3.5.1、创建方法
BRIDGE6DLL_API int64_t createMethodFile(const char *szMethodName);

// 3.5.2、打开方法
BRIDGE6DLL_API int64_t openMethodFile(const char *szFileName);

// 3.5.3、存储方法
BRIDGE6DLL_API bool saveMethodFile(int64_t nHandle, const char *szFileName);

// 3.5.4、关闭方法
BRIDGE6DLL_API bool closeMethodFile(int64_t nHandle);

// 3.5.5、获取方法基础数据
BRIDGE6DLL_API bool getMethodHead(int64_t nHandle, int32_t nHandleType, TMethodHead *pBuffer);

// 3.5.6、设置方法基础数据
BRIDGE6DLL_API bool setMethodHead(int64_t nHandle, int32_t nHandleType, const TMethodHead *pBuffer);

// 3.5.7、获取方法手动事件表
BRIDGE6DLL_API bool getMethodEventList(int64_t nHandle, int32_t nHandleType, TEventList *pBuffer, int32_t nBufferCount, int32_t *pDataCount);

// 3.5.8、设置方法手动事件表
BRIDGE6DLL_API bool setMethodEventList(int64_t nHandle, int32_t nHandleType, const TEventList *pBuffer, int32_t nBufferCount);

// 3.5.9、获取方法组份表
BRIDGE6DLL_API bool getMethodCompList(int64_t nHandle, int32_t nHandleType, TCompList *pBuffer, int32_t nBufferCount, int32_t *pDataCount);

// 3.5.10、设置方法组份表
BRIDGE6DLL_API bool setMethodCompList(int64_t nHandle, int32_t nHandleType, const TCompList *pBuffer, int32_t nBufferCount);

// 3.5.11、获取方法分组表
BRIDGE6DLL_API bool getMethodGroupList(int64_t nHandle, int32_t nHandleType, TGroupList *pBuffer, int32_t nBufferCount, int32_t *pDataCount);

// 3.5.12、设置方法分组表
BRIDGE6DLL_API bool setMethodGroupList(int64_t nHandle, int32_t nHandleType, const TGroupList *pBuffer, int32_t nBufferCount);

// 3.5.13、获取方法校正分段表
BRIDGE6DLL_API bool getMethodSegmentList(int64_t nHandle, int32_t nHandleType, TSegmentList *pBuffer, int32_t nBufferCount, int32_t *pDataCount);

// 3.5.14、设置方法校正分段表
BRIDGE6DLL_API bool setMethodSegmentList(int64_t nHandle, int32_t nHandleType, const TSegmentList *pBuffer, int32_t nBufferCount);

// 3.5.15、获取方法校正表
BRIDGE6DLL_API bool getMethodCalibList(int64_t nHandle, int32_t nHandleType, TCalibList *pBuffer, int32_t nBufferCount, int32_t *pDataCount);

// 3.5.16、设置方法校正表
BRIDGE6DLL_API bool setMethodCalibList(int64_t nHandle, int32_t nHandleType, const TCalibList *pBuffer, int32_t nBufferCount);

// 3.5.17、获取方法校正结果表
BRIDGE6DLL_API bool getMethodCalibResult(int64_t nHandle, int32_t nHandleType, TCalibResult *pBuffer, int32_t nBufferCount, int32_t *pDataCount);

// 3.5.18、设置方法校正结果表
BRIDGE6DLL_API bool setMethodCalibResult(int64_t nHandle, int32_t nHandleType, const TCalibResult *pBuffer, int32_t nBufferCount);

#ifdef _USRDLL
#define CHECK_METHOD_HANDLE(nHandle, nHandleType)                                                           \
    {                                                                                                       \
        if (nHandleType == ORG_HANDLE)                                                                      \
        {                                                                                                   \
            if (OrgFileMap.count(nHandle) <= 0)                                                             \
            {                                                                                               \
                SET_ERROR_(ERR_CODE_ORG_HANDLE_NOT_EXIST, ERR_MESSAGE_ORG_HANDLE_NOT_EXIST, nHandle);       \
                return false;                                                                               \
            }                                                                                               \
        }                                                                                                   \
        else if (nHandleType == METHOD_HANDLE)                                                              \
        {                                                                                                   \
            if (MethodFileMap.count(nHandle) <= 0)                                                          \
            {                                                                                               \
                SET_ERROR_(ERR_CODE_METHOD_HANDLE_NOT_EXIST, ERR_MESSAGE_METHOD_HANDLE_NOT_EXIST, nHandle); \
                return false;                                                                               \
            }                                                                                               \
        }                                                                                                   \
        else                                                                                                \
        {                                                                                                   \
            SET_ERROR_(ERR_CODE_IPARAM_VALUE_INVALID, ERR_MESSAGE_IPARAM_VALUE_INVALID, "nHandleType",      \
                       nHandleType, METHOD_HANDLE, ORG_HANDLE);                                             \
            return false;                                                                                   \
        }                                                                                                   \
    }

extern std::map<int64_t, std::shared_ptr<TMethodFile>> MethodFileMap;
#endif

#endif
